package com.caoxw.Android.CityBus;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.GestureDetector.OnGestureListener;
import android.view.View.OnTouchListener;
import android.widget.ViewFlipper;

public class ActivityEx extends Activity  implements OnTouchListener,OnGestureListener {
    private ViewFlipper mFlipper;  
    private GestureDetector mGestureDetector;      
   
    private static final int FLING_MIN_DISTANCE = 100;      
    private static final int FLING_MIN_VELOCITY = 200;
	
    protected void onCreate(Bundle savedInstanceState) {          
    	super.onCreate(savedInstanceState);  
    	//setContentView(R.layout.main);            
    	//mCurrentLayoutState = 0;          //允许长按住ViewFlipper,这样才能识别拖动等手势          
    	//mFlipper.setLongClickable(true);
    	mGestureDetector = new GestureDetector(this);  

    } 

    public boolean dispatchTouchEvent(MotionEvent ev){
    	mGestureDetector.onTouchEvent(ev);
    	return super.dispatchTouchEvent(ev);//继续传递消息
    }
    public boolean onTouch(View v, MotionEvent event) {
		// TODO Auto-generated method stub
		 return mGestureDetector.onTouchEvent(event);
	}

	public boolean onDown(MotionEvent e) {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
			float velocityY) {
		// TODO Auto-generated method stub
		// 参数解释：   
		// e1：第1个ACTION_DOWN MotionEvent    
		// e2：最后一个ACTION_MOVE MotionEvent    
		// velocityX：X轴上的移动速度，像素/秒    
		// velocityY：Y轴上的移动速度，像素/秒    
		// 触发条件 ：    
		// X轴的坐标位移大于FLING_MIN_DISTANCE，且移动速度大于FLING_MIN_VELOCITY个像素/秒    
		if (e1.getX() - e2.getX() > FLING_MIN_DISTANCE       
		             && Math.abs(velocityX) > FLING_MIN_VELOCITY) {       
			onFlingLeft();       
		     } 
		else if (e2.getX() - e1.getX() > FLING_MIN_DISTANCE       
		             && Math.abs(velocityX) > FLING_MIN_VELOCITY) {       
			onFlingRight();
		     // Fling right    
		}       
		return true;
	}

	public void onFlingLeft(){
		
	}
	public void onFlingRight(){
		
	}
	public void onLongPress(MotionEvent e) {
		// TODO Auto-generated method stub
		
	}

	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
			float distanceY) {
		// TODO Auto-generated method stub
		return false;
	}

	public void onShowPress(MotionEvent e) {
		// TODO Auto-generated method stub
		
	}

	public boolean onSingleTapUp(MotionEvent e) {
		// TODO Auto-generated method stub
		return false;
	}
}
